﻿using System.Reflection;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

namespace VIALUTIONS.InfoPath.FormsHub.InfoPathFormsHubWebPart
{
    /// <summary>
    /// 
    /// </summary>
    public abstract class SPEditorPart : EditorPart
    {
        #region Fields

        private BindingFlags bindingFlags = BindingFlags.Instance | BindingFlags.Public;
        private readonly Assembly _spAssembly = Assembly.Load(@"Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c");
        public Panel ControlPanel = new Panel();
        Panel _propertyPanel;

        #endregion

        #region Methods

        protected SPEditorPart(string partId, string title)
        {
            ID = partId;
            Title = title;
            ControlPanel.Attributes["id"] = ClientID;
            ControlPanel.Style.Add("padding", "1px");
            ChromeType = PartChromeType.None;
        }

        protected override void CreateChildControls()
        {
            base.CreateChildControls();
            _propertyPanel = (Panel)_spAssembly.CreateInstance("Microsoft.SharePoint.WebPartPages.TPPanel", false, bindingFlags, null,
                                                             new object[] { Title, ControlPanel, (ChromeState == PartChromeState.Minimized) },
                                                             null, null);
            if (_propertyPanel != null) Controls.Add(_propertyPanel);
        }

        #endregion
    }
}
